package com.gaoch.simweather.logic.dao

import android.content.Context
import androidx.core.content.edit
import com.gaoch.simweather.MyApplication
import com.gaoch.simweather.logic.model.PlaceResponse
import com.google.gson.Gson

object PlaceDao {
    fun savePlace(place:PlaceResponse.Location){
        sharedPreferences().edit{
            putString("place", Gson().toJson(place))
        }
    }

    fun getSavedPlace():PlaceResponse.Location{
        val placeJson= sharedPreferences().getString("place","")
        return Gson().fromJson(placeJson,PlaceResponse.Location::class.java)
    }

    fun isPlaceSaved()= sharedPreferences().contains("place")

    private fun sharedPreferences()=MyApplication.context.getSharedPreferences("sim_weather",Context.MODE_PRIVATE)
}